<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/include.inc.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/views/layout/base.ref.jsp" %>
    <link rel="stylesheet" href="${ctx}/static/controls/zTree/css/zTreeStyle.css" type="text/css"/>
</head>
<body>
<form method="post" id="form1" action="${ctx}/customsearch/select">
    <input type="hidden" name="arg" id="ids" value="${vo.arg}"/> <input type="hidden" name="code" id="code"
                                                                        value="${vo.code}"/> <input type="hidden"
                                                                                                    name="pageNum"
                                                                                                    value="${vo.pageNum}"/>
    <c:if test="${defaultParam != null }">
        <input type="hidden" name="defaultParam" value="${defaultParam}"/>
    </c:if>
    <div class="col-xs-12">
        <div class="mtrow">
            <div class="mtcolall">
                <c:forEach items="${listControl}" var="con">
                    <label class="mtlabel-auto">${con.controlName}：</label>
                    <c:choose>
                        <c:when test="${con.controlType == 0}">
                            <input type="text" class="mtinput" name="${con.fieldControl}"
                                   value="${vo[con.fieldControl]}"/>
                        </c:when>
                        <c:when test="${con.controlType == 1}">
                            <input type="text" class="mtinput" name="${con.fieldControl}"
                                   value="${vo[con.fieldControl]}"/>
                        </c:when>

                    </c:choose>
                </c:forEach>
                <a class="mtbtn search marginleft" href="#" onclick="submit_onclick()"><span>查询</span></a>
            </div>
        </div>
        <div>
            <ul id="menuTree" class="ztree"></ul>
        </div>
    </div>
    <input type="hidden" name="resultcallback" id="resultcallback" value="${resultcallback}">
</form>
</body>
</html>
<script type="text/javascript" src="${ctx}/static/controls/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx}/static/controls/zTree/js/jquery.ztree.excheck.js"></script>

<script type="text/javascript">
    var setting = {

        data: {
            key: {
                name: "result2"
            },
            simpleData: {
                enable: true,
                idKey: "result1",
                pIdKey: "result11"

            }
        },
        callback: {
            beforeClick: beforeClick
        }
    };

    var zTree;
    $(document).ready(function () {
        var zNodes = ${data};
        zTree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
        zTree.expandAll(true);
    });

    function beforeClick(treeId, treeNode) {
        zTree.checkNode(treeNode, !treeNode.checked, null, true);
        return false;
    }

    function beforeClick(treeId, treeNode) {
        if (treeNode.result1 <= 0) {
            layer.msg("该记录不能选择", {
                icon: 3
            });
            return;
        }
        var result = [{
            "result1": "1"
        }, {
            "result2": ""
        }, {
            "result3": ""
        }, {
            "result4": ""
        }, {
            "result5": ""
        }, {
            "result6": ""
        }, {
            "result7": ""
        }, {
            "result8": ""
        }, {
            "result9": ""
        }, {
            "result10": ""
        }];
        result["result1"] = treeNode.result1;
        result["result2"] = treeNode.result2;
        result["result3"] = treeNode.result3;
        window.parent.sysSelect_getlay(result, result);
        //执行结果回调函数
        if ($("#resultcallback").val()) {
            eval("window.parent.${resultcallback}(result)");
        }
        //当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭

        var check = (treeNode && !treeNode.isParent);
        return check;
    }
</script>
